package com.eascs.web.o2o.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.eascs.app.dao.PageResult;
import com.eascs.common.util.UrlUtil;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.page.SelectDataOption;
import com.eascs.site.view.PaginationRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.web.o2o.web.form.ChannelBusStatisForm;
import com.eascs.web.o2o.web.service.RecommendStaticService;

@RestController
@RequestMapping("/restRecommend")
public class RecommendStaticRestController {
	
	@Autowired
	RecommendStaticService recommendStaticService;

	@RequestMapping("/o2o")
	public PaginationRestResult o2o(ChannelBusStatisForm entity) {
		String o2ourl = "/restRecommend/o2o";
		if (entity != null) {
			String billCode = entity.getBillCode() == null ? "" : entity.getBillCode();
			String loanType = entity.getLoanType() == null ? "" : entity.getLoanType();
			String partnerName = entity.getPartnerName() == null ? "" : entity.getPartnerName();
			String partnerType = entity.getPartnerType() == null ? "" : entity.getPartnerType();
			String loanerName = entity.getLoanerName() == null ? "" : entity.getLoanerName();
			String loanDate = entity.getLoanDate()== null ? "" : entity.getLoanDate();
			String loanDateEnd = entity.getLoanDateEnd()== null ? "" : entity.getLoanDateEnd();
			o2ourl = UrlUtil.appendUrl(o2ourl, "billCode", billCode);
			o2ourl = UrlUtil.appendUrl(o2ourl, "loanType", loanType);
			o2ourl = UrlUtil.appendUrl(o2ourl, "partnerName", partnerName);
			o2ourl = UrlUtil.appendUrl(o2ourl, "partnerType", partnerType);
			o2ourl = UrlUtil.appendUrl(o2ourl, "loanerName", loanerName);
			o2ourl = UrlUtil.appendUrl(o2ourl, "loanDate", loanDate);
			o2ourl = UrlUtil.appendUrl(o2ourl, "loanDateEnd", loanDateEnd);
			o2ourl = o2ourl + "&pageIndex=";
		} else {
			o2ourl = o2ourl + "?pageIndex=";
		}
		entity.setPageSize(10);
		PageResult<Object[]> pageResult = recommendStaticService.getRecommendStaticByPage(entity);
		@SuppressWarnings("unused")
		List<Object[]> data  = pageResult.getData();
		String titles[] = {"贷款单号","借款人","期限","金额(万元)","信贷经理", "经办平台","推荐类型","内部推荐人", "渠道经办人", "渠道类型","渠道名称","放款时间","创建 时间"};
		SelectDataOption[] selectDataOptions = { null,null, null, null, null,null ,null, null, null,new SelectDataOption("OTO_LOAN_TYPE"),null,null,null};
		PaginationInfo o2oPagingInfo = new PaginationInfo(pageResult, titles, o2ourl);
		o2oPagingInfo.setBuildPagingNavigation(true);
		o2oPagingInfo.setFirstRenderColumnIndex(0);
		o2oPagingInfo.setSelectDataOptions(selectDataOptions);
		//o2oPagingInfo.setFormats(new Format[] { null, null, null,  new DecimalFormat(",##0.00"),null, null, null,null, null, null ,null, null ,new SimpleDateFormat("yyyy-MM-dd")});
		o2oPagingInfo.setRendTo("#result_list");
		ViewContext.put("vo", entity);
		return PaginationRestResult.buildPaginationRestResult(o2oPagingInfo);
	}
	
	
}
